package edu.beyond.employment.talent.dao;

import java.util.ArrayList;
import java.util.List;

import edu.beyond.employment.commom.util.DBUtil;
import edu.beyond.employment.talent.entity.TalentEntity;

/**
 * TalentDao
 * 
 * @author GOBeyond
 * @date 2016年9月29日
 */
public class TalentDao {

	public int register(TalentEntity talentEntity) {
		String sql = "INSERT INTO talent VALUES(null, ?, ?, ?, ?, ?, ?, ?, ?)";
		List<Object> paramList = new ArrayList<>();
		paramList.add(talentEntity.getCode());
		paramList.add(talentEntity.getPassword());
		paramList.add(talentEntity.getName());
		paramList.add(talentEntity.getPhone());
		paramList.add(talentEntity.getEmail());
		paramList.add(talentEntity.getAge());
		paramList.add(talentEntity.getGender());
		paramList.add(talentEntity.getHobby());
		return DBUtil.executeUpdate(sql, paramList);
	}

	/**
	 * 求职者登录
	 * 
	 * @param code
	 * @param password
	 * @return
	 */
	public TalentEntity login(String code, String password) {
		String sql = "SELECT id,`name` FROM talent  WHERE code = ? AND password =?";

		return DBUtil.getUniqueResult(TalentEntity.class, sql, code, password);

	}

	public static void main(String[] args) {
		new TalentDao().login("1", "123");

	}

	/**
	 * 个人资料的查询
	 * 
	 * @param id
	 * @return
	 */
	public TalentEntity info(int id) {
		String sql = "SELECT * FROM talent WHERE id = ?";

		return DBUtil.getUniqueResult(TalentEntity.class, sql, id);

	}

	/**
	 * 个人资料的修改
	 * 
	 * @param id
	 * 
	 * @return
	 */
	public int get(TalentEntity talent) {
		String sql = "UPDATE talent SET password =?,name =?,phone = ?,email =?,age=?,gender=?,hobby=? WHERE id = ?";
		return DBUtil.executeUpdate(sql, talent.getPassword(), talent.getName(), talent.getPhone(), talent.getEmail(),
				talent.getAge(), talent.getGender(), talent.getHobby(), talent.getId());
	}

}
